<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="common/include :: header('商品列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="customer-form">
                <div class="select-list">
                    <ul>
                        <li>
                            关键字：<input type="text" name="keyword" placeholder="模糊查询商品名称"/>
                        </li>
                        <li>
                            所在窗口：
                            <select name="wid">
                                <option value="">所有</option>
                                <option th:each="item : ${windows}" th:text="${item.windowName}"
                                        th:value="${item.id}" ></option>
                            </select>
                        </li>
                        <li>
                            上架状态：
                            <select name="state" th:with="items=${@dict.getType('business_goods_state')}">
                                <option value="">所有</option>
                                <option th:each="item : ${items}" th:text="${item.label}"
                                        th:value="${item.value}"></option>
                            </select>
                        </li>
                        <li>
                            销售状态：
                            <select name="saleState" th:with="items=${@dict.getType('business_goods_sale_state')}">
                                <option value="">所有</option>
                                <option th:each="item : ${items}" th:text="${item.label}"
                                        th:value="${item.value}"></option>
                            </select>
                        </li>
                        <li>
                            热卖状态：
                            <select name="isHot" th:with="items=${@dict.getType('business_goods_hot')}">
                                <option value="">所有</option>
                                <option th:each="item : ${items}" th:text="${item.label}"
                                        th:value="${item.value}"></option>
                            </select>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="business:employee:add">
                <i class="fa fa-plus"></i> 添加
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<div class="modal inmodal fade" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-body" style="text-align:center;">
                <img id="imageSrc" src="" alt="" width="300px" height="auto">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
<th:block th:include="common/include :: footer"/>
<script th:inline="javascript">
    var goodsStateTypeData = [[${@dict.getType('business_goods_state')}]];
    var goodsSaleStateTypeData = [[${@dict.getType('business_goods_sale_state')}]];
    var goodsHotTypeData = [[${@dict.getType('business_goods_hot')}]];


    var removeFlag = [[${@permission.hasPermi('business:goods:remove')}]];
    var editFlag = [[${@permission.hasPermi('business:goods:edit')}]];
    var prefix = ctx + "/business/goods";
    $(function () {
        var options = {
            url: prefix + "/query",
            createUrl: prefix + "/addPage",
            updateUrl: prefix + "/editPage?id={id}",
            removeUrl: prefix + "/remove",
            uniqueId: 'id',
            modalName: "商品",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '编号',
                    visible: false
                },
                {
                    field: 'goodsName',
                    title: '商品名称'
                },
                {
                    field: 'coverUrl',
                    title: '商品封面图',
                    formatter: function (value, row, index) {
                        return row.coverUrl ? '<button type="button" class="btn btn-info btn-xs" data-toggle="modal" data-target="#myModal" onclick="viewImage(\'' + row.coverUrl + '\')"><i class="fa fa-search"></i></button>' : '-';
                    }
                },
                {
                    field: 'goodsPrice',
                    title: '商品价格（元）'
                },
                {
                    field: 'goodsNum',
                    title: '商品数量'
                },
                {
                    field: 'saleNum',
                    title: '售量'
                },
                {
                    field: 'windowName',
                    title: '所属窗口'
                },
                {
                    field: 'state',
                    title: '上架状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(goodsStateTypeData, value);
                    }
                },
                {
                    field: 'saleState',
                    title: '销售状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(goodsSaleStateTypeData, value);
                    }
                },
                {
                    field: 'isHot',
                    title: '热卖状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(goodsHotTypeData, value);
                    }
                },
                {
                    field: 'id',
                    title: '商品图片列表',
                    formatter: function (value, row, index) {
                        return row.id ? '<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="imageDetail(\'' + row.id + '\')"><i class="fa fa-list-ul"></i>查看</a>' : '-';
                    }
                },
                {
                    field: 'id',
                    title: '商品属性列表',
                    formatter: function (value, row, index) {
                        return row.id ? '<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="attrDetail(\'' + row.id + '\')"><i class="fa fa-list-ul"></i>查看</a>' : '-';
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var editFlagTemp = editFlag;
                        var removeFlagTemp = removeFlag;

                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlagTemp + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push("<a class='btn btn-danger btn-xs " + removeFlagTemp + "' href='javascript:void(0)' onclick='$.operate.remove(" + row.id + ")'><i class='fa fa-remove'></i>删除</a>");
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });
    function viewImage(imageSrc) {
        $("#imageSrc").attr("src", imageSrc);
    }
    /* 商品图片列表 */
    function imageDetail(goodsId) {
        let url = ctx + '/business/image/listPage?goodsId=' + goodsId;
        $.modal.openTab("商品图片列表", url);
    }
    /* 商品属性列表 */
    function attrDetail(goodsId) {
        let url = ctx + '/business/attr/listPage?goodsId=' + goodsId;
        $.modal.openTab("商品属性列表", url);
    }
</script>
</body>
</html>